package productDeptConfig

import (
	"context"
	"devops-super/api/configs/v1"
	"devops-super/internal/model/entity"
	"devops-super/internal/service"
	"github.com/gogf/gf/v2/os/gtime"
)

// GetPageLst 分页获取部门产品配置列表
func (*ControllerV1) GetPageLst(ctx context.Context, req *v1.ProductDeptConfigGetPageLstReq) (res *v1.ProductDeptConfigGetPageLstRes, err error) {
	res = &v1.ProductDeptConfigGetPageLstRes{}
	res.PageLstRes, err = service.ProductDeptConfig().GetPageLst(ctx, req)
	return
}

// Add 新增部门产品配置
func (*ControllerV1) Add(ctx context.Context, req *v1.ProductDeptConfigAddReq) (res *v1.ProductDeptConfigAddRes, err error) {
	config := &entity.AppProductDeptConfig{
		ProductId:   req.ProductId,
		DeptId:      req.DeptId,
		GroupName:   req.GroupName,
		ConfigKey:   req.ConfigKey,
		ConfigValue: req.ConfigValue,
		Remark:      req.Remark,
		CreatedAt:   gtime.Now(),
	}
	err = service.ProductDeptConfig().Add(ctx, config)
	return
}

// Upt 更新部门产品配置
func (*ControllerV1) Upt(ctx context.Context, req *v1.ProductDeptConfigUptReq) (res *v1.ProductDeptConfigUptRes, err error) {
	config := &entity.AppProductDeptConfig{
		Id:          req.Id,
		ProductId:   req.ProductId,
		DeptId:      req.DeptId,
		GroupName:   req.GroupName,
		ConfigKey:   req.ConfigKey,
		ConfigValue: req.ConfigValue,
		Remark:      req.Remark,
		UpdatedAt:   gtime.Now(),
	}
	err = service.ProductDeptConfig().Upt(ctx, config)
	return
}

// Del 删除部门产品配置
func (*ControllerV1) Del(ctx context.Context, req *v1.ProductDeptConfigDelReq) (res *v1.ProductDeptConfigDelRes, err error) {
	err = service.ProductDeptConfig().Del(ctx, req.Id)
	return
}

// GetOne 获取单条部门产品配置
func (*ControllerV1) GetOne(ctx context.Context, req *v1.ProductDeptConfigGetOneReq) (res *v1.ProductDeptConfigGetOneRes, err error) {
	res1, err := service.ProductDeptConfig().GetOne(ctx, req.Id)
	if err != nil {
		return
	}
	res = new(v1.ProductDeptConfigGetOneRes)
	res.Info = res1
	return
}

// GetOptions 获取部门产品配置选项
func (*ControllerV1) GetOptions(ctx context.Context, req *v1.ProductDeptConfigGetOptionsReq) (res *v1.ProductDeptConfigGetOptionsRes, err error) {
	res, err = service.ProductDeptConfig().GetOptions(ctx, req)
	return
}

// GetGroupConfigs 获取部门产品配置组
func (*ControllerV1) GetGroupConfigs(ctx context.Context, req *v1.GetProductDeptGroupConfigsReq) (res *v1.GetProductDeptGroupConfigsRes, err error) {
	res, err = service.ProductDeptConfig().GetGroupConfigs(ctx, req)
	return
}

// SetGroupConfigs 保存部门产品配置组
func (*ControllerV1) SetGroupConfigs(ctx context.Context, req *v1.SetProductDeptGroupConfigsReq) (res *v1.SetProductDeptGroupConfigsRes, err error) {
	res = &v1.SetProductDeptGroupConfigsRes{}
	err = service.ProductDeptConfig().SetGroupConfigs(ctx, req)
	return
}